<?php

//针对到期的推送方式制0，判断到期的状态制为0
require 'common.inc.php';
//群发消息到期提示,正式环境上开启注释
$result=$db->query("select openid,itemid from {$DT_PRE}weixin_user WHERE pushstatus=3 and endtime<=".time());
$a=0;
while($r=$db->fetch_array($result)) {
	$openid=$r['openid'];
	$word="您的微信及邮件提醒服务已结束，继续使用请联系客服".$DT['telephone'];
	$type='text';
	require DT_ROOT.'/api/weixin/init.inc.php';
    $arr = $wx->send($openid, $type, $word);
	$post = array();
	$post['content'] = $word;
	$post['type'] = 'reply';
	$post['openid'] = $openid;
	$post['editor'] = $_username;
	$post['addtime'] = $DT_TIME;
	$post['misc']['type'] = $type;
	$post['misc'] = $post['misc'] ? serialize($post['misc']) : '';
	$post = daddslashes($post);
	$sql = '';
	foreach($post as $k=>$v) {
			$sql .= ",$k='$v'";
	}
	$time=time();
	$db->query("UPDATE {$DT_PRE}weixin_user SET pushwx='0',pushemail='0',pushstatus='2',endtime=".$time." WHERE itemid=".$r['itemid']);
	$db->query("INSERT INTO {$DT_PRE}weixin_chat SET ".substr($sql, 1));				
	$a++;
}
$b=0;
$result1=$db->query("select itemid,email from {$DT_PRE}email_user WHERE pushstatus=3 and endtime<=".time());
while($r1=$db->fetch_array($result1)) {
	$db->query("UPDATE {$DT_PRE}email_user SET  pushemail='0',pushstatus='2',endtime=".$time." WHERE itemid=".$r1['itemid']);
	$b++;
}

echo "此次更新微信订阅".$a."条,邮箱推送".$b."条";

	
